﻿using AnesSystem.Models;
using AnesSystem.Services;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// AccountUpDate.xaml 的交互逻辑
    /// </summary>
    public partial class AccountUpDateCtrl : UserControl
    {
        private AccountUpDateCtrlViewModel accountUpDateCtrlViewModel;
        List<string> _roles = new List<string>() { "管理员", "医生", "工程师", "手术医生", "护士", "麻醉医生", "" };
        List<string> _titles = new List<string>() { "主任医师", "副主任医师", "主治医师", "住院医师", "医师", "实习医师", "规培医师", "进修医师", "手术医生", "手术室护士", "工程师", "" };

        public AccountUpDateCtrl()
        {
            InitializeComponent();
            accountUpDateCtrlViewModel = AccountUpDateCtrlViewModel.Instance;
            this.DataContext = accountUpDateCtrlViewModel;
            _title.ItemsSource = _titles;
            _role.ItemsSource = _roles;

            //_mzfs.ItemsSource = _mafs;
            //_mzfs.Text = rcvm.Plm.Schedule.Mzfs;
            ////this..Text= rcvm.Plm.Patient.Brxm;
            //_taishu.Text = rcvm.Plm.Schedule.Pbts;
            //_roomsCmbCtrl.Text = rcvm.Plm.Schedule.Pbssjh;
        }
        public AccountUpDateCtrl(AccountModel account, bool ise)
        {
            InitializeComponent();
            accountUpDateCtrlViewModel = AccountUpDateCtrlViewModel.Instance;
            accountUpDateCtrlViewModel.Account = account;
            accountUpDateCtrlViewModel.IsEnabled = ise;
            this.DataContext = accountUpDateCtrlViewModel;
            _title.ItemsSource = _titles;
            _role.ItemsSource = _roles;
            //_mzfs.ItemsSource = _mafs;
            //_mzfs.Text = rcvm.Plm.Schedule.Mzfs;
            ////this..Text= rcvm.Plm.Patient.Brxm;
            //_taishu.Text = rcvm.Plm.Schedule.Pbts;
            //_roomsCmbCtrl.Text = rcvm.Plm.Schedule.Pbssjh;
        }
        private void Button_Update_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(workID.Text))
            {
                caveat.Text = "工号未填写！";
            }
            else if (workID.Text.Length < 1 && AccountService.Instance.seachAccountByLoginName(workID.Text) != null)
            {
                workID.Text = "";
                caveat.Text = "工号重复！请重新填写.";
            }
            else if (string.IsNullOrEmpty(trueName.Text))
            {
                caveat.Text = "医生名称未填写！";
            }
            else if (string.IsNullOrEmpty(_pws.Password))
            {
                _pws.Password = "";
                caveat.Text = "密码未填写！";
            }
            else if (string.IsNullOrEmpty(_pwsY.Password))
            {
                _pwsY.Password = "";
                caveat.Text = "确认密码未填写！";
            }
            else
            {
                if (!_pws.Password.Equals(_pwsY.Password))
                {
                    _pws.Password = "";
                    _pwsY.Password = "";
                    caveat.Text = "密码不一致";
                }
                else
                {
                    accountUpDateCtrlViewModel.ShowPwd=_pws.Password;
                    save();
                }
            }
        }

        private void save()
        {
            accountUpDateCtrlViewModel.Save();
            DrugAndEventWindow.Instance.CloseWin();
        }

        private void Button_Return_Click(object sender, RoutedEventArgs e)
        {
            DrugAndEventWindow.Instance.CloseWin();
        }
    }
}
